package org.apache.hadoop.dfs;

import java.util.Date;

/** A report on the status of a DataNode.
 *
 * @see DistributedFileSystem#getDataNodeStats
 */
public class DataNodeReport {
  String name;
  String host;
  long capacity;
  long remaining;
  long lastUpdate;
  
  /** The name of the datanode. */
  public String getName() { return name; }

  /** The hostname of the datanode. */
  public String getHost() { return host; }

  /** The raw capacity. */
  public long getCapacity() { return capacity; }

  /** The raw free space. */
  public long getRemaining() { return remaining; }

  /** The time when this information was accurate. */
  public long getLastUpdate() { return lastUpdate; }

  @Override
  public String toString() {
    StringBuilder buffer = new StringBuilder();
    long c = getCapacity();
    long r = getRemaining();
    long u = c - r;
    buffer.append("Name: ").append(name).append("\n");
    buffer.append("Total raw bytes: ").append(c).append(" (").append(DFSShell.byteDesc(c)).append(")").append("\n");
    buffer.append("Used raw bytes: ").append(u).append(" (").append(DFSShell.byteDesc(u)).append(")").append("\n");
    buffer.append("% used: ").append(DFSShell.limitDecimal(((1.0 * u) / c) * 100)).append("%").append("\n");
    buffer.append("Last contact: ").append(new Date(lastUpdate)).append("\n");
    return buffer.toString();
  }

}
